home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…stman Always Clicks Twice / ADC Developer CD (1993-01) (''The Postman Always Clicks Twice'')_iso / Dev.CD 199301.iso / Development Platforms / Apple II / System 6.0 Sample Code / Sanity / Sanity.aii < prev    next >
Encoding:
Text File  |  1990-07-29  |  4.6 KB  |  333 lines  |  [TEXT/MPS ]

  1. *******************************************************************
  2. *
  3. * SanityInit -- a temporary init to load DAs and Inits from a
  4. *               common folder when you're juggling multiple
  5. *               System folders
  6. *
  7. * by David A. Lyons, 28-Jul-90
  8. *
  9. * Put SanityInit in all your *:System folders, and put all the
  10. * NDAs, CDAs, PIFs, and TIFs you want to load in *:Common.
  11. *
  12. *******************************************************************
  13. *
  14. * 28-Jul-90 DAL --> v1.0
  15. *   Initial coding (borrowing code for directory scan and
  16. *     InitialLoad from Nifty List 3.1p source)
  17. *
  18. *
  19. *******************************************************************
  20.  
  21.     include 'm16.memory'
  22.     include 'm16.loader'
  23.     include 'm16.util'
  24.     include 'm16.gsos'
  25.     include 'm16.desk'
  26.  
  27. tPIF    equ $b6
  28. tTIF    equ $b7
  29. tNDA    equ $b8
  30. tCDA    equ $b9
  31.  
  32. cr    equ 13
  33.  
  34. Sanity    PROC
  35.     Case    off
  36.  
  37.     brl @go
  38.     dc.b cr
  39.     dc.b 'Sanity Init 1.0 by David A. Lyons 28-Jul-90',cr
  40.     dc.b '     P.O. Box 875, Cupertino CA 95015',cr
  41.     dc.b '           GEnie: DAVE.LYONS',cr
  42.     dc.b '        America Online: Dave Lyons',cr
  43.     dc.b cr
  44.  
  45. @go    phb
  46.     phk
  47.     plb
  48.     php
  49.     rep #$30
  50.  
  51.     jsr doScan
  52.  
  53.     plp
  54.     plb
  55.     rtl
  56.  
  57. doScan    jsr SetPrefix0
  58.     jsr LoadThings
  59.     jsr FixPrefix0
  60.     rts
  61.  
  62. *
  63. * Set Prefix 0 to the directory
  64. *
  65. SetPrefix0    jsr CheckP16
  66.     bcs @x
  67.     _GetPrefixGS origPrefix
  68.     _SetPrefixGS newPrefix    
  69. @x    rts
  70.  
  71. *
  72. * Put prefix 0 back how it was before SetPrefix0
  73. *
  74. FixPrefix0    jsr CheckP16
  75.     bcs @x
  76.     _SetPrefixGS restorePrefix    
  77. @x    rts
  78.  
  79. origPrefix dc.w 2
  80.     dc.w 0
  81.     dc.l tempPrefix
  82. restorePrefix dc.w 2
  83.     dc.w 0
  84.     dc.l tempPrefix+2
  85. newPrefix dc.w 2
  86.     dc.w 0
  87.     dc.l CommonPath
  88.  
  89. tempPrefix dc.w 67
  90.     ds 65
  91.  
  92. CommonPath    dc.w 8
  93.     dc.b '*:Common'
  94.  
  95. *
  96. * Load Things from the *:Common directory (prefix 0 is already here)
  97. *
  98. LoadThings    _OpenGS OpenTheDir
  99.     bcs ltDone
  100.     lda dirRef
  101.     sta dirRef2
  102.     sta dirRef3    
  103.  
  104. GetNextName    _GetDirEntryGS GetDirEnt
  105.     bcs ltClose    
  106.     lda entAux
  107.     bmi @inactive
  108.     lda entType
  109.     jsr Load1Thing
  110. @inactive    bra GetNextName
  111.  
  112. ltClose    _CloseGS CloseTheDir
  113. ltDone    rts
  114.  
  115. OpenTheDir    dc.w 3
  116. dirRef    dc.w 0
  117.     dc.l ZeroColon
  118.     dc.w $0001        ;read only
  119. ZeroColon    dc.b 2,0,'0:'
  120.  
  121. CloseTheDir    dc.w 1
  122. dirRef3    dc.w 0
  123.  
  124. GetDirEnt    dc.w 13
  125. dirRef2    dc.w 0
  126.     dc.w 0,1,1        ;flags, base, displacement
  127.     dc.l fileNameBuff
  128.     dc.w 0        ;entry num
  129. entType    dc.w 0        ;filetype
  130.     dc.l 0        ;eof
  131.     dc.l 0        ;blocks
  132.     dc.l 0,0,0,0    ;create/mod date/time
  133.     dc.w 0        ;access
  134. entAux    dc.l 0        ;auxtype
  135.  
  136. fileNameBuff
  137.     dc.w 36
  138.     ds 34
  139. *
  140. * Load1Thing--load the file in fileNameBuff (filetype in A)
  141. *
  142. Load1Thing    sta typTable
  143.     ldx #IDTable-typTable
  144. @srch    dex
  145.     dex
  146.     cmp typTable,x
  147.     bne @srch
  148.     stx foundX
  149.  
  150.     lda IDTable,x
  151.     tay
  152.     beq @ltDone        ;id=0 means don't load it
  153.     jsr LoadIt
  154.     bcs @ltDone
  155.  
  156.     ldx foundX
  157.     lda GoTable,x
  158.     dec a
  159.     pha
  160.     lda theID
  161.     ldx theAddr+2
  162.     ldy theAddr
  163. @ltDone    rts
  164.  
  165. typTable    dc.w $7777,tCDA,tNDA,tPIF,tTIF
  166. IDTable    dc.w $0000,$5000,$5000,$A000,$A000
  167. GoTable    dc.w GoXXX,GoCDA,GoNDA,GoPIF,GoTIF
  168. foundX    dc.w 0
  169. *
  170. * GoXXX ("Go" routines called with A=ID, XY=address)
  171. *
  172. GoXXX    rts
  173. *
  174. * GoCDA
  175. *
  176. GoCDA    pha
  177.     pha
  178.     phx
  179.     phy
  180.     _FindHandle
  181.     _InstallCDA
  182.     rts
  183. *
  184. * GoNDA
  185. *
  186. GoNDA    pha
  187.     pha
  188.     phx
  189.     phy
  190.     _FindHandle
  191.     _InstallNDA
  192.     rts
  193. *
  194. * GoPIF
  195. *
  196. GoPIF    jsr SetupStk    ;screws B
  197.     
  198.     pea 0        ;space for "unload-me" flag
  199.     jsl JmpTheAddr
  200.     rep #$30
  201.     pla
  202.     sta >theResult
  203.     
  204.     jsr RestoreStk
  205.     lda theResult
  206.     lsr a
  207.     bcc @keep
  208.     lda theID
  209.     jsr ShutdownA
  210. @keep    rts
  211.  
  212. theResult    dc.w 0
  213. *
  214. * GoTIF
  215. *
  216. GoTIF    jsr SetupStk    ;screws B
  217.     jsr JmpTheAddr
  218.     jsr RestoreStk
  219.     jsr ShutdownA
  220.     rts
  221. *
  222. * JmpTheAddr -- transfer control to theAddr, with A=theID, XY=0
  223. *
  224. JmpTheAddr    lda >theAddr+2
  225.     sep #$20
  226.     pha
  227.     rep #$20
  228.     lda >theAddr
  229.     dec a
  230.     pha
  231.     lda >theID
  232.     ldx #0
  233.     txy
  234.     rtl
  235. *
  236. * ShutDownA -- UserShutDown ID=A
  237. *
  238. ShutdownA    pha        ;space for new ID
  239.     lda theID
  240.     pha
  241.     pea 0
  242.     _UserShutDown
  243.     pla
  244.     rts
  245. *
  246. * SetupStk--switch to the thing's own stack/dp, if any
  247. *
  248. SetupStk    plx
  249.  
  250.     tdc
  251.     sta myDP
  252.     tsc
  253.     sta myStack
  254.     
  255.     lda theDP
  256.     beq @noDP
  257.     tcd
  258.     clc
  259.     adc theDPSize
  260.     dec a
  261.     tcs
  262. @noDP    
  263.     pea $ffff
  264.     plb
  265.     plb
  266.     
  267.     phx
  268.     rts
  269. *
  270. * RestoreStk--go back to using my own stack/dp
  271. *
  272. RestoreStk    rep #$30
  273.     plx
  274.     phk
  275.     plb
  276.     lda myStack
  277.     tcs
  278.     lda myDP
  279.     tcd
  280.     phx
  281.     rts
  282.  
  283. myStack    dc.w 0
  284. myDP    dc.w 0
  285.  
  286. *
  287. * LoadIt--filename in fileNameBuff, ID in Y carry/A=err,
  288. *   theID, theAddr, theDP, theDPSize
  289. *
  290. LoadIt    pha
  291.     pha
  292.     pha
  293.     pha
  294.     pha
  295.     phy        ;mem ID in Y
  296.     pushlong #FileNameBuff+2
  297.     pea 1        ;no special memory
  298.     pea 1        ;name is a GS/OS string
  299.     _InitialLoad2
  300.     plx        ;memID
  301.     stx theID
  302.     plx        ;address low
  303.     stx theAddr
  304.     plx        ;address high
  305.     stx theAddr+2
  306.     plx        ;direct-page location
  307.     stx theDP
  308.     plx        ;direct-page size
  309.     stx theDPSize
  310.     rts
  311.  
  312. theID    dc.w 0
  313. theAddr    dc.l 0
  314. theDP    dc.w 0
  315. theDPSize    dc.w 0
  316.  
  317. *
  318. * CheckP16 -- return SEC if 16-bit OS is not available
  319. *
  320. CheckP16    lda $e100ba
  321.     bne noP16z
  322.     lda $e100bc
  323.     and #$00ff
  324.     cmp #$01
  325.     bne noP16z
  326.     clc
  327.     rts
  328. noP16z      sec
  329.     rts
  330.  
  331.     endp
  332.     end
  333.